<template>
  <div>
    <el-dialog :title="dialogtitle" width="800px" class="icon-dialog" :visible.sync="show" :before-close="closeForm"
      append-to-body @open="open">
      <el-form ref="form" :size="size" :model="form" :rules="rules"
        :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
        <el-row>
          <el-col :span="24">
            <el-form-item label="计算方式">
              <el-radio-group v-model="form.city_discount_method">
                <el-radio :label="0">百分比</el-radio>
                <el-radio label="1">加减金额</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="城市商品/服务价格加权">
              <el-select v-if="form.city_discount_method==1" v-model="form.discount_addsubtract"
                style="width:80px;margin-right: 8px;" placeholder="加">
                <el-option label="加" value="+" />
                <el-option label="减" value="-" />
              </el-select>
              <el-input v-model="form.city_discount" style="width:500px;" auto-complete="off" clearable
                placeholder="请输入">
                <template v-if="form.city_discount_method==0" slot="append">%</template>
                <template v-if="form.city_discount_method==1" slot="append">元</template>
              </el-input>

              <div class="help-block">设置后，所代理的城市的所有服务和商品都会加权计算价格</div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="loading" type="primary" @click="submit">
          <span v-if="!loading">保 存</span>
          <span v-else>提 交 中...</span>
        </el-button>
        <el-button @click="closeForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    name: 'cityconfig',
    components: {

    },
    props: {
      show: {
        type: Boolean,
        default: false
      },
      size: {
        type: String,
        default: 'small'
      },
      info: {
        type: Object
      }
    },
    data() {
      return {
        dialogtitle: '',
        cidarray: [],
        form: {
          city_discount_method: 0
        },
        loading: false,
        rules: {
        }
      }
    },
    watch: {
      show(val) {}
    },
    methods: {
      open() {
        this.dialogtitle = '城市价格设置'
        this.form = this.info
      },
      submit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.$api.post('/operatingcity/cityconfigupdate', this.form).then(res => {
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.$emit('refesh_list')
              this.closeForm()
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      closeForm() {
        this.$emit('update:show', false)
        this.loading = false
        if (this.$refs['form'] !== undefined) {
          this.$refs['form'].resetFields()
        }
      }
    }
  }
</script>
